package com.sbj.controller;

import cn.hutool.core.convert.Convert;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.sbj.dto.req.ExtensionReq;
import com.sbj.dto.res.ExtensionRes;
import com.sbj.entity.Extension;
import com.sbj.service.ExtensionService;
import com.zmh.framework.config.BaseCommonInterface;
import com.zmh.framework.util.Result;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.validation.Valid;
import java.util.List;

/**
 * @author summer
 * @version 1.0
 * @date 2024/8/11 10:11
 * 推广比例
 */
@RestController
@RequestMapping(value = "/extension")
@AllArgsConstructor
public class ExtensionController implements BaseCommonInterface<ExtensionReq, ExtensionRes> {

    private final ExtensionService extensionService;

    @Override
    public Result<String> save(@Valid ExtensionReq extensionReq) {
        extensionService.saveOrUpdate(Convert.convert(Extension.class, extensionReq));
        return Result.successResult();
    }

    @Override
    public Result<String> del(Integer id) {
        extensionService.removeById(id);
        return Result.successResult();
    }

    @Override
    public Result<Page<ExtensionRes>> lists(ExtensionReq extensionReq) {
        return Result.successResult(extensionService.lists(extensionReq));
    }

    @Override
    public Result<ExtensionRes> findById(Integer id) {
        return Result.successResult(Convert.convert(ExtensionRes.class,extensionService.getById(id)));
    }

    @Override
    public Result<String> batchDel(List<ExtensionRes> list) {
        return null;
    }
}
